package com.ruoyi.quartz.task;


import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.ruoyi.edu.domain.Activity;
import com.ruoyi.edu.service.IActivityService;
import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;


@Component("eduTask")

public class EduTask {
    public static void main(String[] args) {

        String content = "【通知】欢迎各位同学参加本周的课程";
//        String content = "【通知】欢迎各位同学参加第7周的课程";

        sendDingTalkMsg(content);

    }

    private static void sendDingTalkMsg(String content) {

        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=96529c9f6d244763b9c033916911788d6a6ce8570f53ee82e5580c2c08e4e3d6");

        OapiRobotSendRequest request = new OapiRobotSendRequest();

        request.setMsgtype("text");

        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();

        text.setContent(content);

        request.setText(text);


        try {

            OapiRobotSendResponse response = client.execute(request);

        } catch (ApiException e) {

            e.printStackTrace();

            throw new RuntimeException("发送钉钉消息失败");

        }

    }

    @Autowired

    private IActivityService activityService;


    public void checkActivities() {

//        System.out.println("执行定时任务：检查社会活动记录是否完整");
//        StringBuilder sb = new StringBuilder();
//        for (Activity activity : activityService.selectIncompleteList()) {
//
//            System.out.println("社会活动记录'" + activity.getDetail() + "'未提供活动链接");
//            sb.append("社会活动记录'" + activity.getDetail() + "'未提供活动链接\n");
//        }

//        sendDingTalkMsg(sb.toString());
        String text = "【通知】hello i am zjw";
        sendDingTalkMsg(text);
    }

}